package com.hx.voice.recognition.admin.rpc;

import com.ace.cache.annotation.Cache;
import com.hx.voice.recognition.admin.rpc.service.PermissionService;
import com.hx.voice.recognition.api.vo.authority.PermissionInfo;
import com.hx.voice.recognition.api.vo.user.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @descripe：用户服务提供者
 * @company：南京华讯方舟通讯设备有限公司
 * @author：zhoujinbing
 * @time：2019/6/13 15:12
 * @version：V1.0
 */
@RestController
@RequestMapping("api")
public class UserRest {

    @Autowired
    private PermissionService permissionService;

    /**
     * @description 获取所有菜单以及操作权限
     * @method  getAllPermissionInfo
     * @param  []
     * @return java.util.List<com.hx.zjb.security.api.vo.authority.PermissionInfo>
     * @date: 2019/6/13 16:13
     * @author:zhoujinbing
     */
    @Cache(key = "permission")
    @RequestMapping(value = "/permissions",method = RequestMethod.GET)
    public List<PermissionInfo>  getAllPermissionInfo()
    {
        return permissionService.getAllPermissionInfo();
    }

    /**
     * @description 根据用户名获取权限
     * @method  getPermissionByUserName
     * @param  [username]
     * @return java.util.List<com.hx.zjb.security.api.vo.authority.PermissionInfo>
     * @date: 2019/6/13 16:16
     * @author:zhoujinbing
     */
    @Cache(key = "permission:u{1}")
    @RequestMapping(value = "/user/un/{username}/permissions",method = RequestMethod.GET)
    public List<PermissionInfo> getPermissionByUserName(@PathVariable("username") String username)
    {
        return permissionService.getPermissionByUserName(username);
    }

    @RequestMapping(value = "/user/validate",method = RequestMethod.POST)
    public UserInfo validate(@RequestBody Map<String,String> body)
    {
        return permissionService.validate(body.get("username"),body.get("password"));
    }

}